"""
__author__="yanwei"
__describe__="登录接口获取token"
__API__="/plan/step"
"""

import json
from conf.readConfig import ReadConfig
import requests

host = ReadConfig().get_url("test_http_url")


class GetToken():
    def setUp(self):
        print("**********开始执行***********")

        # 获取域名
        self.host = ReadConfig().get_url("test_http_url")
        print(self.host)
        # 请求参数存放位置
        self.username = ReadConfig().get_account("username")
        self.password = ReadConfig().get_account("password")
        self.vercode = ReadConfig().get_account("vercode")

    def teardown(self):
        print("------------执行结束-----------")

    def login(self):
        resp = requests.post(url=host + "/auth/login", data={"user_name": "yanwei", "password": "cs123456"})
        auth = resp.text
        authjson = json.loads(auth)
        return authjson['data']["authorization"]

    def sendlogincode(self):
        resp = requests.post(url=host + "/sms/sendLoginCode", data={"authorization": GetToken().login()})

    def mobile(self):
        resp = requests.post(url=host + "/auth/login/mobile",
                             data={"code": "234234", "authorization": GetToken().login()})
        authroization = resp.text
        tokenjson = json.loads(authroization)
        token = tokenjson["data"]["authorization"]
        print(token)
        return token


if __name__ == "__main__":
    GetToken().mobile()
